﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using Gift.DAL;
using Gift.Model;


namespace WebSite.admin.warehouse
{
    public partial class stockOutOrderPrinter : BaseAdmin
    {
        readonly DALStockOrder theOrder = new DALStockOrder();
        readonly DALStockOrderGoods theOrderGoods = new DALStockOrderGoods();
        readonly dalCompany theCompany = new dalCompany();
        tbCompany oCompany;

        tbStockOrder oStockOrder;
        DataTable tbGoods;
        StringBuilder _sbGoodsList;

        public StringBuilder SbGoodsList
        {
            get { return _sbGoodsList; }
        }

        string _stockOrderCode;

        public string StockOrderCode
        {
            get { return _stockOrderCode; }
        }

        public string PrintDate
        {
            get { return DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); }

        }
        string _stockCompany;

        public string StockCompany
        {
            get { return _stockCompany; }
        }

        string _linker;

        public string Linker
        {
            get { return _linker; }
        }
        string _linkerPhone;

        public string LinkerPhone
        {
            get { return _linkerPhone; }
        }
        string _goodsToDate;

        public string GoodsToDate
        {
            get { return _goodsToDate; }
        }

        decimal _sumOrderPrice;

        public string SumOrderPrice
        {
            get { return "¥" + _sumOrderPrice + "--元"; }
        }
        public string SumOrderPriceSupper
        {
            get { return Gift.Utile.MathLibrary.CmycurD(_sumOrderPrice); }
        }
        string _stockOrderRemark;

        public string StockOrderRemark
        {
            get { return _stockOrderRemark; }
        }
        string _stockCompanyAddress;

        public string StockCompanyAddress
        {
            get { return _stockCompanyAddress; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BuildForm();
            }
        }

        void BuildForm()
        {
            oStockOrder = theOrder.GetModel(int.Parse(Request.QueryString["id"]));
            this._stockOrderCode = oStockOrder.stockOrderCode;
            this._goodsToDate = ((DateTime)oStockOrder.goodsToDate).ToString("yyy年MM月dd日");
            this._linker = oStockOrder.linker;
            this._linkerPhone = oStockOrder.linkerPhone;
            this._stockOrderRemark = oStockOrder.remark;

            oCompany = theCompany.GetModel((int)oStockOrder.stockCompanyId);
            this._stockCompany = oCompany.Name;
            this._stockCompanyAddress = oCompany.Provence + "," + oCompany.City + "," + oCompany.Address;

            tbGoods = theOrderGoods.GetGoodsListByOrderCode(oStockOrder.stockOrderCode).Tables[0];

            _sbGoodsList = new StringBuilder();
            int i = 1;
            foreach (DataRow dr in tbGoods.Rows)
            {

                _sbGoodsList.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td></tr>"
                                       , i.ToString()
                                        , dr["goodsCode"].ToString()
                                        , dr["goodsName"].ToString()
                                        , dr["modelTypeName"].ToString()
                                         , dr["goodsCount"].ToString()
                                        , dr["goodsStockPrice"].ToString()
                                        , dr["sumOrderPrice"].ToString()
                                        );
                _sumOrderPrice = _sumOrderPrice + decimal.Parse(dr["sumOrderPrice"].ToString());
                i++;
            }


        }
    }
}